﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pumpkin.FrameBase;


namespace KBEngine
{  
    public class KBEngineApp
    {
        public static KBEngineApp app;
        public NetworkInterfaceBase networkInterface = null;

        private KBEConfigs args_;
        private CrossDomainInstance crossApp;

        public KBEngineApp(KBEConfigs args)
        {
            app = this;
            args_ = args;
            Event.registerBuildin("_closeNetwork", this, "_closeNetwork");

            crossApp = CrossInstanceFactory.Instance.CreateWithInstantial(BaseCrossType.KBEngineApp);
        }

        public KBEConfigs getInitArgs()
        {
            return args_;
        }

        public void _closeNetwork(NetworkInterfaceBase networkInterface)
        {
            networkInterface.close();
        }

        public UInt16 serverErr(UInt16 errno)
        {
            Debug.LogError(errno);
            return errno;
        }

        #region CrossMethods
        public void InitializeApp(KBEConfigs configs)
        {
            crossApp.Invoke("InitializeApp", configs);
        }

        public void destroy()
        {
            crossApp.Invoke("destroy");
        }

        public void process()
        {
            crossApp.Invoke("process");
        }

        public string getServerVersion()
        {
            return (string)crossApp.Invoke("getServerVersion");
        }
        #endregion
    }
}